package ch.jamme.conf.def;

import ch.jamme.conf.*;

/**
 * Defines the naming convention to be used while generating marshalling an object in xml.
 * This default implementation just returns some constant values regardless of the objects being marshalled.
 * @author Mario Fusco
 */
public class DefaultNamingConvention implements NamingConvention {

	private static final String ID_ATTRIBUTE = "id";
	private static final String ID_REF_ATTRIBUTE = "idref";
	private static final String CLASS_ATTRIBUTE = "className";
	
	private static final String ROOT_ELEMENT = "root";
	private static final String LIST_ITEM_ELEMENT = "list_item";
	private static final String MAP_ENTRY_ELEMENT = "map_entry";
	private static final String MAP_ENTRY_KEY_ELEMENT = "map_entry_key";
	private static final String MAP_ENTRY_VALUE_ELEMENT = "map_entry_value";
	
	/**
	 * Returns the name of the attribute that contains the class name of the marshalled object
	 */
	public String getClassNameAttribute() {
		return CLASS_ATTRIBUTE;
	}

	/**
	 * Returns the name of the attribute that contains a value that uniquely identifies 
	 * a given marshalled object in the xml tree
	 */
	public String getIdentifierAttribute() {
		return ID_ATTRIBUTE;
	}

	/**
	 * Returns the name of the attribute that contains the value of an object identifier 
	 * that references the xml of an already marshalled object
	 */
	public String getIdentifierReferenceAttribute() {
		return ID_REF_ATTRIBUTE;
	}

	/**
	 * Returns the tag name of the xml root element resulting from the marshalling of the object itself
	 * @param object The object to be marshalled
	 */
	public String getRootTag(Object object) {
		return ROOT_ELEMENT;
	}
	
	/**
	 * Returns the tag name of the elements resulting from the marshalling of each item of a given list
	 * @param containingClass The class of the object containing the list to be marshalled
	 * @param fieldName The name of the field containing the list
	 */
	public String getListItemTag(Class<?> containingClass, String fieldName) {
		return LIST_ITEM_ELEMENT;
	}

	/**
	 * Returns the tag name of the elements resulting from the marshalling of each entry of a given map
	 * @param containingClass The class of the object containing the map to be marshalled
	 * @param fieldName The name of the field containing the map
	 */
	public String getMapItemTag(Class<?> containingClass, String fieldName) {
		return MAP_ENTRY_ELEMENT;
	}

	/**
	 * Returns the tag name of the elements resulting from the marshalling of each key of a given map
	 * @param containingClass The class of the object containing the map to be marshalled
	 * @param fieldName The name of the field containing the map
	 */
	public String getMapKeyTag(Class<?> containingClass, String fieldName) {
		return MAP_ENTRY_KEY_ELEMENT;
	}

	/**
	 * Returns the tag name of the elements resulting from the marshalling of each value of a given map
	 * @param containingClass The class of the object containing the map to be marshalled
	 * @param fieldName The name of the field containing the map
	 */
	public String getMapValueTag(Class<?> containingClass, String fieldName) {
		return MAP_ENTRY_VALUE_ELEMENT;
	}
}
